
#include "Page.h"


void close_tab_callback(GtkWidget *widget,gpointer data) {
	Page *page = (Page *)data;
	app.closePage(page);
}


Page::Page() : tab(0),label(0),page(0) {
app.printf("Page::Page()");
}

Page::~Page() {
app.printf("Page::~Page()");
}

void Page::open(const char *t,GtkWidget *p) {
app.printf("Page::open()");
	GtkWidget *button,*image;

	tab = gtk_hbox_new(FALSE,3);
	label = gtk_label_new(t);
	gtk_box_pack_start(GTK_BOX(tab),label,TRUE,TRUE,0);

	button = gtk_button_new();
	gtk_button_set_relief(GTK_BUTTON(button),GTK_RELIEF_NONE);
	gtk_widget_set_name(button,"tab-close-button");
	image = gtk_image_new_from_stock(GTK_STOCK_CLOSE,GTK_ICON_SIZE_MENU);
	gtk_container_add(GTK_CONTAINER(button),image);
	g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(close_tab_callback),(gpointer)this);
	gtk_box_pack_start(GTK_BOX(tab),button,FALSE,FALSE,0);

	page = p;
	g_object_set_data(G_OBJECT(page),"PageObject",(gpointer)this);
	app.openPage(*this);
}

void Page::close() {
app.printf("Page::close()");
	delete this;
}

void Page::setTabLabelText(const char *t) {
app.printf("Page::setTab(tab=%s)",t);
	gtk_label_set_text(GTK_LABEL(label),t);
}


void Page::setColor(cairo_t *cr,int c) {
	cairo_set_source_rgb(cr,((float)((c>>16)&0xff))/255.,((float)((c>>8)&0xff))/255.,((float)(c&0xff))/255.);
}
